/**
 * @asignatura: Procesadores de Lenguajes.
 * @autor:      Anthony Vittorio Russo Cabrera
 * @curso:      2012/2013
 * @practica:   04 - ANTLRv3.4 Identificación de tokens
 * @descripcion:
 */
package pl.p04;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.Lexer;
import org.antlr.runtime.Token;

import pl.p04.case_insensitivity.ANTLRFileStreamCaseInsensitivity;
import pl.p04.case_insensitivity.ANTLRInputStreamCaseInsensitivity;

public class Procesador {

  public static final int C   = 0;
  public static final int XML = 1;

  public static void main(String args[]) throws IOException {

    // Determinar parámetros
    int option = -1;
    ANTLRStringStream input = null;
    try {
      switch (args.length) {
        case 1: // InputStream
          option = Integer.parseInt(args[0]);
          input = new ANTLRInputStreamCaseInsensitivity(System.in);
          break;
        case 2: // FileStream
          option = Integer.parseInt(args[0]);
          input = new ANTLRFileStreamCaseInsensitivity(args[1]);
          break;
        default:
          System.err.println("java Procesador option (file)?");
          System.exit(0);
      }// switch

      // Núcleo de la práctica
      Lexer lexer = null;
      if      (option == C)   lexer = new CLexer(input);
      else if (option == XML) lexer = new XMLLexer(input);
      else                    System.exit(0);
      Token token;
      for (token = lexer.nextToken(); token.getType() != Token.EOF; token = lexer.nextToken()) {
        System.out.println(token);
      }// for

      
    // Execpciones
    } catch (FileNotFoundException e) {
      System.err.println("File Not Found: \"" + args[1] + "\"");
      e.printStackTrace();
    } catch (IOException e) {
      System.err.println("Input/Output Error");
      e.printStackTrace();
    }// try-catch

  } // main

}// Procesador
